package com.ruizhong.centercontroll.controller;


import com.ruizhong.centercontroll.entity.TProgram;
import com.ruizhong.centercontroll.service.TProgramService;
import com.ruizhong.centercontroll.util.Result;
import com.ruizhong.centercontroll.util.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/program/api")
public class TProgramController {

    @Autowired
    private TProgramService tProgramService;

    @PostMapping("/submitNewProgram")
    public Result submitNewProgram(@RequestBody TProgram tProgram){
        tProgramService.submitNewProgram(tProgram);
        return new Result(ResultCode.success,null,null);
    }

    @PostMapping("/updateProgramInfo")
    public Result updateProgramInfo(@RequestBody TProgram tProgram){
        tProgramService.updateProgramInfo(tProgram);
        return new Result(ResultCode.success,null,null);
    }

    @GetMapping("/getAllProgramList")
    public Result getAllProgramList(){
        List<TProgram>  programs= tProgramService.getAllProgramList();
        return new Result(ResultCode.success,null,programs);
    }

    @GetMapping("/getProgramDetailById/{id}")
    public Result getProgramDetailById(@PathVariable(value = "id") Integer id){
       TProgram  program= tProgramService.getProgramDetailById(id);
        return new Result(ResultCode.success,null,program);
    }
    @DeleteMapping("/deleteProgramById/{id}")
    public Result deleteProgramById(@PathVariable(value = "id") Integer id){
    tProgramService.deleteProgramById(id);
        return new Result(ResultCode.success,null,null);
    }


    @GetMapping("/getProgramBySQId/{id}")
    public Result getProgramBySQId(@PathVariable(value = "id") Integer id){
        List<TProgram>  programs= tProgramService.getProgramBySQId(id);
        return new Result(ResultCode.success,null,programs);
    }
}
